package com.algorithm.labuladong.palindrome;

/**
 * @author: tzj
 * @create: 2021-08-10
 **/
public class Palindrome {
    public static void main(String[] args) {
        String s = "sas";
        System.out.println(isPalindrome(s));
    }

    /**
     * 判断是否回文字符串(双指针法)
     *
     * @param s
     * @return
     */
    public static boolean isPalindrome(String s) {
        if (s.length() <= 1) {
            return true;
        }
        int left = 0, right = s.length() - 1;
        while (left < right) {
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
